import spacy
from nltk.sentiment import SentimentIntensityAnalyzer


def analyze_content(content):
    # 词性标注

    # 创建情感分析器实例并执行情感分析
    sia = SentimentIntensityAnalyzer()
    sentiment_scores = sia.polarity_scores(content)
    is_positive_sentiment = sentiment_scores['pos'] > sentiment_scores['neg']

    # 执行依存句法分析和问候语检测
    nlp = spacy.load('en_core_web_sm')
    doc = nlp(content)

    # 存储结果的列表
    sentences = []
    sentence_structure = []
    greeting_detected = False

    # 获取句子结构、词性标注和问候语检测结果
    for sent in doc.sents:
        sentences.append(sent.text)

        for token in sent:
            sentence_structure.append({
                'word': token.text,
                'dep': token.dep_,
                'pos': token.pos_,
                'tag': token.tag_
            })

            if token.pos_ == 'INTJ':
                greeting_detected = True

    # 将结果字典返回
    return {
        'sentiment_scores': sentiment_scores,
        'is_positive_sentiment': is_positive_sentiment,
        'sentences': sentences,
        'sentence_structure': sentence_structure,
        'greeting_detected': greeting_detected
    }
